import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { APP_GUARD } from '@nestjs/core';
import { Logger } from 'winston';

import { AppController } from './app.controller';
import { JwtAuthGuard } from './common/guards';
import { AccountModule, DatabaseModule, PermissionModule, RoleModule, MenuModule, AuthModule } from './modules';

const loadEnvFile = () => {
  const envFile = [`.env.${process.env.NODE_ENV}`, '.env'];
  return envFile;
};

@Module({
  imports: [
    ConfigModule.forRoot({
      envFilePath: loadEnvFile(),
      isGlobal: true,
    }),
    DatabaseModule,
    AuthModule,
    AccountModule,
    RoleModule,
    PermissionModule,
    MenuModule,
  ],
  controllers: [AppController],
  providers: [
    // {
    //   provide: APP_GUARD,
    //   useClass: JwtAuthGuard,
    // },
    Logger,
  ],
})
export class AppModule {}
